<template>
  <!-- 消息更多 -->
  <div class="page_padding">
    <MyNavBar @goback="goback" :title="title" />
    <div class="tab_con">
      <div class="result">
        <div class="desc">
          <div class="big_title">{{ detailsData.assessmentTitle }}</div>
          <div class="little_title">{{ detailsData.createByOrgName }}</div>
          <div class="num">{{ userNumStr }}</div>
        </div>
        <div class="table">
          <table>
            <thead>
              <tr>
                <th>序号</th>
                <th>人员身份</th>
                <th>姓名</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(item, index) in userList" :key="item.id">
                <td>{{ index + 1 }}</td>
                <td>{{ item.userType }}</td>
                <td>{{ item.userName }}</td>
              </tr>
            </tbody>
          </table>
        </div>
        <div class="audit">
          <div class="result">
            <div class="res_title">
              <span class="text">* 审核结果</span>
            </div>
            <div class="res_btn" v-if="detailsData.assessmentStatus === '-1'">
              <span
                :class="{ choose_cative: item.id == chooseStatus }"
                @click="resultChange(item)"
                v-for="item in examineDataList"
                :key="item.id">
                {{ item.name }}
              </span>
            </div>
            <div class="res_btn" v-else>
              <span class="choose_cative">
                {{ detailsData.assessmentStatus === '0' ? '审核不通过' : '审核通过' }}
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="fead_boot" v-if="detailsData.assessmentStatus === '-1'">
      <div class="btn_li" @click="submit">提 交</div>
    </div>
  </div>
</template>

<script>
import { getAssessmentDetail, updateAssessmentCheckStatus } from '@api/api-democratic.js'

import MyNavBar from '@com/MyNavBar'
export default {
  name: 'evaluationManageSum',
  components: { MyNavBar },
  props: {},
  data() {
    return {
      title: '测评管理',
      id: this.$route.query.id,
      userInfo: JSON.parse(localStorage.userInfo),
      routeQuery: this.$route.query,
      detailsData: {},
      userList: [],
      userNumStr: '',
      examineDataList: [
        {
          name: '审定通过',
          id: '2',
        },
        {
          name: '审定不通过',
          id: '3',
        },
      ],
      chooseStatus: '',
    }
  },
  created() {},
  mounted() {
    this.initdata()
  },
  methods: {
    initdata() {
      getAssessmentDetail({ id: this.id }).then(res => {
        let data = res.data
        this.detailsData = { ...data }
        this.getUserNum(data.leaders, data.noLeaders, data.nonCivil)
        data.leaders.forEach(item => {
          item.userType = '领导成员'
        })
        data.noLeaders.forEach(item => {
          item.userType = '非领导成员'
        })
        data.nonCivil.forEach(item => {
          item.userType = '非公务员成员'
        })
        let allUsers = [...data.leaders, ...data.noLeaders, ...data.nonCivil]
        this.userList = allUsers.concat()
      })
    },
    goback() {
      this.$router.go(-1)
    },
    getUserNum(leaders, noLeaders, nonCivil) {
      let totalStr = ''
      totalStr += leaders && leaders.length > 0 ? `领导成员${leaders.length}人` : ''
      totalStr +=
        noLeaders && noLeaders.length > 0
          ? leaders && leaders.length
            ? `，非领导成员${noLeaders.length}人`
            : `非领导成员${noLeaders.length}人`
          : ''
      totalStr +=
        nonCivil && nonCivil.length > 0
          ? noLeaders && noLeaders.length
            ? `，非公务员成员${nonCivil.length}人`
            : `非公务员成员${nonCivil.length}人`
          : ''
      this.userNumStr = totalStr
    },
    resultChange({ id }) {
      if (this.chooseStatus != id) {
        this.chooseStatus = id
      }
    },
    submit() {
      let that = this
      if (!that.chooseStatus) {
        return that.$toast.fail('请选择审核结果后再提交')
      }
      let sugg = that.chooseStatus === '2' ? '审核通过' : '审核不通过'
      that.$dialog
        .confirm({
          title: '提示',
          message: '确定' + sugg + '参与的民主测评人员？',
        })
        .then(() => {
          updateAssessmentCheckStatus({
            assessmentId: that.id,
            assessmentStatus: that.chooseStatus,
          }).then(res => {
            if (res.status === 200) {
              that.$toast.success('审核成功')
              setTimeout(() => {
                that.$router.go(-1)
              }, 500)
            }
          })
        })
        .catch(() => {})
    },
  },
}
</script>

<style lang="scss" scoped>
.tab_con {
  width: 100%;
  background-color: #fff;
  z-index: 10;
  padding-bottom: 70px;
  .desc {
    text-align: center;
    // font-size: 14px;
    margin-top: 15px;
    padding: 0 12px;
    .big_title {
      font-size: 16px;
      font-weight: bold;
    }
    .little_title {
      font-weight: bold;
      margin-top: 8px;
    }
    .num {
      color: #666;
      margin-top: 10px;
      padding: 0 12px;
      text-align: left;
    }
  }
  .table {
    margin-top: 8px;
    margin-bottom: 10px;
    // font-size: 14px;
    padding: 0 12px;
    table {
      width: 100%;
      border-right: 1px solid #eeeeee;
      border-top: 1px solid #eeeeee;
      thead {
        background-color: #f2f2f2;
      }
      tbody {
        text-align: center;
      }
      th,
      td {
        text-align: center;
        // word-break: keep-all; /* for ie */
        // white-space: nowrap; /* for chrome */
        padding: 8px 3px;
        border-left: 1px solid #eeeeee;
        border-bottom: 1px solid #eeeeee;
        font-size: 13px;
      }
    }
  }
  .audit {
    .result {
      .res_title {
        font-size: 14px;
        font-weight: bold;
        color: #333;
        padding: 12px 14px 6px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        .text {
          background-image: linear-gradient(#ffffff 50%, #f9f1e8);
        }
      }
      .res_btn {
        font-size: 13px;
        padding: 0 14px;
        margin-top: 10px;
        display: flex;
        span {
          border: 1px solid #a7a7a7;
          border-radius: 2px;
          width: 80px;
          height: 30px;
          line-height: 30px;
          color: #a7a7a7;
          text-align: center;
          margin-right: 10px;
        }
        .choose_cative {
          color: #c09144;
          border-color: #c09144;
        }
      }
    }
  }
}
</style>
